package com.ddwl.message.controller;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.message.domain.sms.SentSmsDomain;
import com.ddwl.message.domain.sms.bo.LoanSentSmsFlowBo;
import com.ddwl.message.domain.sms.bo.TempSentSmsBo;
import com.ddwl.message.domain.sms.dao.dto.SentSmsFlowDto;
import com.ddwl.message.service.SmsService;
import com.ddwl.schema.bo.base.PageBo;
import com.ddwl.schema.bo.gate.SmsBo;
import com.ddwl.schema.vo.base.PageVo;
import com.ddwl.schema.vo.base.RestVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author Fu Zhaohui
 */
@Api(tags = "短信服务")
@RequestMapping("/sms")
@RestController
public class SmsController extends BaseController {

    @Resource
    private SmsService smsService;
    @Resource
    private SentSmsDomain sentSmsDomain;

    @PostMapping("/code")
    @Auth(required = false)
    @ApiOperation("获取验证码")
    public RestVo getAuthCode(@Valid @RequestBody SmsBo bo) {
        smsService.getAuthCode(bo);
        return RestVo.ok("短信发送成功，请注意查收短信");
    }

    @PostMapping("/sent")
    @Auth(product = BaseEnum.ProductEnum.API)
    @ApiOperation(value = "发送短信",hidden = true)
    public RestVo setSms(@Valid @RequestBody TempSentSmsBo  bo) {
        sentSmsDomain.sentSms(bo);
        return RestVo.ok("短信发送成功，请注意查收短信");
    }

    @PostMapping("/getSmsPage")
    @Auth(product = BaseEnum.ProductEnum.API)
    @ApiOperation(value = "查询短信列表")
    public RestVo<PageVo<LoanSentSmsFlowBo>> getSmsPage(@RequestBody PageBo<SentSmsFlowDto> bo) {
        PageVo<LoanSentSmsFlowBo> page = sentSmsDomain.getPage(bo);
        return RestVo.ok(page);
    }

    @PostMapping("/getSmsCount")
    @Auth(product = BaseEnum.ProductEnum.API)
    @ApiOperation(value = "查询短信列表")
    public RestVo<Integer> getSmsCount(@RequestBody SentSmsFlowDto bo) {
        Integer smsCount = sentSmsDomain.getSmsCount(bo);
        return RestVo.ok(smsCount);
    }

    @PostMapping("/changeId")
    @ApiOperation("把id反转成时间戳")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo changeId(){
        smsService.changeId();
        return RestVo.ok();
    }
}
